/*
 * @Copyright: Copyright (c) 2030 吴周海
 * @Author: wzh200x@126.com
 * @Date: 2025-10-09 10:33:09
 * @LastEditors: wzh200x@126.com
 * @LastEditTime: 2025-10-28 11:15:37
 * @FilePath: \gogamewebserver\goGameWebServer\main.go
 * @Description: 文件功能描述
 */
package main

import (
	"goGameWebServer/internal/common/config"
	"goGameWebServer/internal/common/logger"
	"goGameWebServer/internal/defines/entityName"
	"goGameWebServer/internal/manager/cachemanager"
	"goGameWebServer/internal/manager/databasemanager"
	"goGameWebServer/internal/manager/platformmanager"
	"goGameWebServer/internal/model/entity"
	_ "goGameWebServer/internal/packed"
	"goGameWebServer/internal/register"

	_ "github.com/gogf/gf/contrib/drivers/mysql/v2"

	_ "goGameWebServer/internal/register/registerInit"

	"github.com/gogf/gf/v2/os/gctx"

	"goGameWebServer/internal/cmd"
)

func main() {
	// 加载配置
	config.AppOptions = config.LoadConfig()
	// 从环境变量加载配置
	config.LoadConfigFromEnv(config.AppOptions)
	// 加载平台配置
	platformOptions := config.LoadPlatformConfigs()
	// 初始化日志
	logger.NewLogger(config.AppOptions)
	databasemanager.ManagerDatabase().InitDatabases(gctx.GetInitCtx(), *config.AppOptions)
	cachemanager.ManagerCache().Init(gctx.GetInitCtx(), *config.AppOptions)
	platformmanager.ManagerPlatform().Init(platformOptions)
	// 处理ServerKey,如果数据库里面有,那么就使用数据库里面的
	serverM := register.GetModel(entityName.EntityName_Server)
	serverMData := serverM.GetEntityData().(*entity.ServerModelData)
	serverMData.Zone = config.AppOptions.ServerID
	serverM.LoadEntityDataFromDB(nil)
	if serverMData.WebSecret != "" {
		config.AppOptions.ServerKey = serverMData.WebSecret
	}
	cmd.Main.Run(gctx.GetInitCtx())
}
